package com.vcar.LDiceClient.command.handler
{	
	import com.vcar.LDiceClient.config.GlobalEventName;
	import com.vcar.LDiceClient.config.ModuleName;
	import com.vcar.LDiceClient.config.ProxyNames;
	import com.vcar.LDiceClient.core.HeartBeatTick;
	import com.vcar.LDiceClient.core.ModWindowManager;
	import com.vcar.LDiceClient.dataproxy.DateProxy;
	import com.vcar.LDiceClient.dataproxy.RequestMessage;
	import com.vcar.LDiceClient.dataproxy.ResponseMessage;
	import com.vcar.LDiceClient.dataproxy.module.ModuleInfo;
	import com.vcar.LDiceClient.dataproxy.user.UserProxy;
	import com.vcar.LDiceClient.manager.TickManager;
	
	import flash.geom.Point;
	
	import org.puremvc.as3.patterns.facade.Facade;

	/**
	 * 对socket得到的数据进行处理 
	 * @author Rices
	 */	
	public class SocketDataHandler
	{
		public function SocketDataHandler()
		{
		}
		

		
		
		/**
		 * 接收到用户登成功的信息，进行处理 
		 * @param data
		 * 
		 */		
		public static function loginSuccHandle(data:ResponseMessage):void
		{
			if(data.succ)
			{
				var proxy:UserProxy = Facade.getInstance().retrieveProxy(ProxyNames.UserProxy) as UserProxy;
				var m:ModuleInfo = new ModuleInfo();
				m.url=ModuleName.HALL_MODULE;
				proxy.sendNotification(GlobalEventName.MODULE_CHANGE, m);
				proxy.sendNotification(GlobalEventName.APP_LOGIN_SUCC, null);
				
				//登录成功后
				proxy.currentUserVO.username = data.object.user.userId;
				
				//得到服务器时间
				var getServerTimeRequest:RequestMessage = new RequestMessage();
				getServerTimeRequest.type = 1;
				getServerTimeRequest.subtype=2;
				ApplicationFacade.getInstance().send(getServerTimeRequest);

				//启动心跳
				TickManager.instance.addTick(new HeartBeatTick());
			}
			
		}
		
		/**
		 * 登录失败 
		 * @param data
		 * 
		 */		
		public static function loginFail(data:ResponseMessage):void
		{
			ModWindowManager.getInstance().showAlert(data.object.msg);
		}
		
		
		/**
		 * 同步服务器时间 
		 * @param data
		 * 
		 */		
		public static function onGetServerTime(data:Object):void
		{
			var p:DateProxy=Facade.getInstance().retrieveProxy(ProxyNames.DateProxy) as DateProxy;
			p.setServerTime(data.object.stime);
		}
		
	}
}